
 /*********************************************************
 *
 *  Project:      HZFlashCards
 *
 *  Class:        HTMLListPane
 *
 *  File name:    HTMLListPane.java
 *
 *
 *    SVN:
 *
 *    $Rev$:
 *    $Date$:
 *    $LastChangedBy$:
 *
 *    $HeadURL$:
 *
 **********************************************************/

package com.eastmountain.chinese.gui;

import java.util.Vector;

import com.eastmountain.chinese.common.HTMLStrings;
import com.eastmountain.chinese.db.flashcards.records.ChineseElementProperties;

/*********************************************************
 *
 *  Class:        HTMLReviewListPane
 *
 **********************************************************/

@SuppressWarnings("serial")
public class HTMLReviewListPane extends HTMLListPane {

    private Vector<ChineseElementProperties> chineseElementReviewList;

    private String[][] fieldValues;
    private static String[] tdClasses = { "center", "center", "left", "right", "right" };

    public HTMLReviewListPane() {
    	
    	// TODO take care of word review list

        System.out.println( "\nHTMLReviewListPane() invoked\n" );

    }

    public void displayHTML( Vector<ChineseElementProperties> chineseElementReviewList ) {

        System.out.println( "\nHTMLReviewListPane.displayHTML() invoked\n" );

        this.chineseElementReviewList = chineseElementReviewList;

        createHTMLListPanel( "Review List" );

        fieldValues = extractFieldValues( chineseElementReviewList );

        String trTag = "<tr>";
        String tdTag = "<td>";
        String tableData;
        int i1 = 0;
        int i2 = 0;

        startHTML();

        htmlBody.append( "<table id=\"mytable\">" + HTMLStrings.nl + "<tbody>" + HTMLStrings.nl
                        + "<caption>Character Review List</caption>" + HTMLStrings.nl );

        htmlBody.append( "<tr>" + HTMLStrings.nl
                        + "  <th class=\"narrow\">Character</th>" + HTMLStrings.nl
                        + "  <th class=\"narrow\">PinYin</th>" + HTMLStrings.nl
                        + "  <th class=\"definition\">Definition</th>" + HTMLStrings.nl
                        + "  <th class=\"narrow\">Lesson</th>" + HTMLStrings.nl
                        + "  <th class=\"narrow\">Level</th>" + HTMLStrings.nl
                        + "</tr>" + HTMLStrings.nl );

        i1 = 0;

        for ( @SuppressWarnings("unused")
        ChineseElementProperties chineseElementProperties : chineseElementReviewList ) {

            if ( i1 % 2 == 0 ) {

                trTag = "<tr class=\"alt\">";

            } else {

                trTag = "<tr>";

            }

            htmlBody.append( trTag );

            for ( i2 = 0; i2 < ChineseElementProperties.NUMBER_OF_FIELD_VALUES; i2++ ) {

                tdTag = "    <td class=\"" + HTMLReviewListPane.tdClasses[ i2 ] + "\">";

                tableData = tdTag + fieldValues[ i1 ][ i2 ] + "</td>" + HTMLStrings.nl;
                htmlBody.append( tableData );

            }

            htmlBody.append( "</tr>" + HTMLStrings.nl );

            i1++;

        }

        htmlBody.append( "</tbody>" + HTMLStrings.nl + "</table>" + HTMLStrings.nl );

        finishHTML();

    }

    private String[][] extractFieldValues( Vector<ChineseElementProperties> chineLessonFlashCardSet ) {

        String[][] fieldValues
            = new String[ chineLessonFlashCardSet.size() ][ ChineseElementProperties.NUMBER_OF_FIELD_VALUES ];
        String lessonNumber= "";


        for ( int i = 0; i < chineLessonFlashCardSet.size(); i++ ) {

            fieldValues[ i ][ 0 ] = chineLessonFlashCardSet.elementAt( i ).getChineseElement();
            fieldValues[ i ][ 1 ] = chineLessonFlashCardSet.elementAt( i ).getPinyin();
            fieldValues[ i ][ 2 ] = chineLessonFlashCardSet.elementAt( i ).getEnglish();
            lessonNumber = Integer.toString( chineLessonFlashCardSet.elementAt( i ).getLessonNumber() );
            fieldValues[ i ][ 3 ] = lessonNumber;
            fieldValues[ i ][ 4 ] = chineLessonFlashCardSet.elementAt( i ).getLevel();
        }

        return fieldValues;

    }

}
